import { call, put, takeEvery } from "redux-saga/effects"
import { login, getAllUsers } from "../../apis/users"

// 登录模块
function* asyncLogin({ payload }) {
    const res = yield call(login, payload)
    const { token, userInfo } = res.data.data
    //    执行派发
    yield put({ type: "initUser", payload: { token, userInfo } })
}

//用户列表
function* asyncAllUsers({ payload }) {
    const res = yield call(getAllUsers, payload)
    const data = res.data.data
    //    执行派发
    yield put({ type: "initAllUsers", payload: { data } })
}

export default function* index() {
    yield takeEvery("loginSaga", asyncLogin)
    yield takeEvery("usersSaga", asyncAllUsers)
}